//
//  QYXRankingInforCollectionCell.m
//  OpenYourEyes
//
//  Created by dllo on 16/6/7.
//  Copyright © 2016年 Google AdWords. All rights reserved.
//

#import "QYXRankingInforCollectionCell.h"
#import "UIImageView+WebCache.h"


@implementation QYXRankingInforCollectionCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
 
        self.rankingTopInforImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_rankingTopInforImageView];
        
        
        self.rankingBottomInforImageView = [[UIImageView alloc] init];
        self.rankingBottomInforImageView.userInteractionEnabled = YES;
        self.rankingBottomInforImageView.transform = CGAffineTransformRotate(self.rankingBottomInforImageView.transform, M_PI);
        [self.contentView addSubview:_rankingBottomInforImageView];
        
    
        
        self.rankingCoverInforImageView = [[UIImageView alloc] init];
        self.rankingCoverInforImageView.transform = CGAffineTransformRotate(self.rankingCoverInforImageView.transform, M_PI);
        self.rankingCoverInforImageView.userInteractionEnabled = YES;
        [self.rankingBottomInforImageView addSubview:_rankingCoverInforImageView];
        
  
        
        self.rankingInforTitleLabel = [[UILabel alloc] init];
        self.rankingInforTitleLabel.textColor = [UIColor whiteColor];
        self.rankingInforTitleLabel.font = [UIFont fontWithName:@"FZLTZCHJW--GB1-0" size:17];
        [self.rankingCoverInforImageView addSubview:_rankingInforTitleLabel];
        
        
        self.rankingInforDurationLabel = [[UILabel alloc] init];
        self.rankingInforDurationLabel.textColor = [UIColor whiteColor];
        self.rankingInforDurationLabel.font = [UIFont fontWithName:@"FZLTXIHJW--GB1-0" size:13];
        [self.rankingCoverInforImageView addSubview:_rankingInforDurationLabel];
        
        
        self.rankingInforContentLabel = [[UILabel alloc] init];
        self.rankingInforContentLabel.numberOfLines = 0;
        self.rankingInforContentLabel.textColor = [UIColor whiteColor];
        self.rankingInforContentLabel.font = [UIFont fontWithName:@"FZLTXIHJW--GB1-0" size:13];
        [self.rankingCoverInforImageView addSubview:_rankingInforContentLabel];
        
        
        self.lineView = [[UIView alloc] init];
        self.lineView.backgroundColor = [UIColor whiteColor];
        [self.rankingCoverInforImageView addSubview:_lineView];
        
        
        self.loveRankView = [[QYXTopRankingView alloc] init];
        [self.rankingCoverInforImageView addSubview:_loveRankView];
        
        
        self.shareRankView = [[QYXTopRankingView alloc] init];
        [self.rankingCoverInforImageView addSubview:_shareRankView];
        
        
        self.commentRankView = [[QYXTopRankingView alloc] init];
        self.commentRankView.userInteractionEnabled = YES;
        UITapGestureRecognizer *commentTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapcommentRankView)];
        [self.commentRankView addGestureRecognizer:commentTap];
        [self.rankingCoverInforImageView addSubview:_commentRankView];
        
 
        
        self.downLoadRankView = [[QYXTopRankingView alloc] init];
        [self.rankingCoverInforImageView addSubview:_downLoadRankView];
        
        
        
        self.playCoverImageView = [[UIImageView alloc] init];
        self.playCoverImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapPlayRecogizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPlay:)];
        [self.playCoverImageView addGestureRecognizer:tapPlayRecogizer];
        [self.contentView addSubview:_playCoverImageView];

        
//     //定时器:
//        
//       [NSTimer scheduledTimerWithTimeInterval:9 target:self selector:@selector(timeAction) userInfo:nil repeats:YES];
 
        
    }
    return self;
}


#pragma mark -- 定时器图片缩放
- (void)timeAction

{
   [UIView animateWithDuration:5 animations:^{
       
       self.rankingTopInforImageView.transform = CGAffineTransformMakeScale(1.2, 1.2);
       
       
   } completion:^(BOOL finished) {
       
       [UIView animateWithDuration:4 animations:^{

           self.rankingTopInforImageView.transform = CGAffineTransformIdentity;
           
       } completion:^(BOOL finished) {
           
           
           
       }];
       
       
   }];
   
    
    
}


#pragma mark -- 轻拍方法:

- (void)didTapcommentRankView


{
    
    [self.delegate pushCommentPageWithId:_rankingInforModel.id];

}

#pragma mark -- 播放视频

- (void)tapPlay:(UITapGestureRecognizer *)sender
{
  
    [self.delegate tapPlay:self.rankingInforModel];
    
  
}




- (void)layoutSubviews

{
    [super layoutSubviews];
    
  //图片:
    
    self.rankingTopInforImageView.frame = CGRectMake(0, 0, kScreenWidth, (kScreenHeight - 64) / 2);
    
    self.rankingBottomInforImageView.frame = CGRectMake(0, self.rankingTopInforImageView.bounds.size.height, self.rankingTopInforImageView.bounds.size.width, self.rankingTopInforImageView.bounds.size.height);
    
    self.rankingCoverInforImageView.frame = self.rankingBottomInforImageView.bounds;
  //文本:
    
    self.rankingInforTitleLabel.frame = CGRectMake(20, 0, self.rankingCoverInforImageView.bounds.size.width - 40, self.rankingCoverInforImageView.bounds.size.height / 3 / 2);
    
    self.rankingInforDurationLabel.frame = CGRectMake(20, self.rankingInforTitleLabel.bounds.size.height, self.rankingInforTitleLabel.bounds.size.width / 3, self.rankingInforTitleLabel.bounds.size.height);
    
    self.rankingInforContentLabel.frame = CGRectMake(20, self.rankingInforTitleLabel.bounds.size.height + self.rankingInforDurationLabel.bounds.size.height, self.rankingCoverInforImageView.bounds.size.width - 40, self.rankingCoverInforImageView.bounds.size.height / 3);
    
    self.lineView.frame = CGRectMake(20, self.rankingInforTitleLabel.bounds.size.height - 1, self.rankingInforTitleLabel.bounds.size.width - 60, 1);
    
    
    
    self.loveRankView.frame = CGRectMake(0, self.rankingCoverInforImageView.bounds.size.height / 3 * 2, self.rankingCoverInforImageView.bounds.size.width / 5 , self.rankingCoverInforImageView.bounds.size.height /3 / 2);
    
    self.shareRankView.frame = CGRectMake(self.loveRankView.bounds.size.width, self.rankingCoverInforImageView.bounds.size.height / 3 * 2, self.rankingCoverInforImageView.bounds.size.width / 5 , self.rankingCoverInforImageView.bounds.size.height / 3 / 2);
    
    
    self.commentRankView.frame = CGRectMake(self.loveRankView.bounds.size.width * 2, self.rankingCoverInforImageView.bounds.size.height / 3 * 2, self.rankingCoverInforImageView.bounds.size.width / 5 , self.rankingCoverInforImageView.bounds.size.height / 3 / 2);
    
    
    self.downLoadRankView.frame = CGRectMake(self.loveRankView.bounds.size.width * 3, self.rankingCoverInforImageView.bounds.size.height / 3 * 2, self.rankingCoverInforImageView.bounds.size.width / 5 , self.rankingCoverInforImageView.bounds.size.height / 3 / 2);
    
    self.playCoverImageView.center = self.rankingTopInforImageView.center;
    
    self.playCoverImageView.frame = CGRectMake((self.rankingTopInforImageView.bounds.size.width - kScreenWidth / 5 ) / 2, (self.rankingTopInforImageView.bounds.size.height - kScreenWidth / 5 ) / 2, kScreenWidth / 5, kScreenWidth / 5);
    
    

}



- (void)setRankingInforModel:(QYXTopRankingModel *)rankingInforModel

{
    if (_rankingInforModel != rankingInforModel) {
        _rankingInforModel = rankingInforModel;
        
        [self.rankingTopInforImageView sd_setImageWithURL:[NSURL URLWithString:rankingInforModel.coverModel.feed] placeholderImage:kPlaceHolderImage completed:nil];
        
        [self.rankingBottomInforImageView sd_setImageWithURL:[NSURL URLWithString:rankingInforModel.coverModel.detail] placeholderImage:kPlaceHolderImage completed:nil];
        
        [self.rankingCoverInforImageView sd_setImageWithURL:[NSURL URLWithString:rankingInforModel.coverModel.blurred] placeholderImage:kPlaceHolderImage completed:nil];
        
        self.rankingInforTitleLabel.text = rankingInforModel.title;
        
        self.rankingInforDurationLabel.text = [NSString stringWithFormat:@"时长:  %d%ld' %ld''", 0, rankingInforModel.duration / 60, rankingInforModel.duration % 60];
        
        self.rankingInforContentLabel.text = rankingInforModel.content;
        
        
        self.loveRankView.staImageView.image = [UIImage imageNamed:@"love"];
        
        self.shareRankView.staImageView.image = [UIImage imageNamed:@"share"];
        
        self.commentRankView.staImageView.image = [UIImage imageNamed:@"comment"];
        
        self.downLoadRankView.staImageView.image = [UIImage imageNamed:@"downLoad"];
        
        self.playCoverImageView.image = [UIImage imageNamed:@"play"];
        
        self.shareRankView.staNumberLabel.text = [NSString stringWithFormat:@"%@", [rankingInforModel.consumption objectForKey:@"shareCount"]];
        
        self.loveRankView.staNumberLabel.text = [NSString stringWithFormat:@"%@", [rankingInforModel.consumption objectForKey:@"collectionCount"]];
        
        
        self.commentRankView.staNumberLabel.text = [NSString stringWithFormat:@"%@", [rankingInforModel.consumption objectForKey:@"replyCount"]];
        
        
        self.downLoadRankView.staNumberLabel.text = @"缓存";
  
        
    }
    
    
    
}




@end
